#include "list.h"

Recond_node* create_list_recond(void)
{
	Recond_node* head = malloc(sizeof(Recond_node));
	head->next = NULL;
	head->front = NULL;
	return head;
}

Student* create_node_stu(const char* id,const char* name,const char* password)			//创建学生结构体
{
	Student* stu = malloc(sizeof(Student));
	strcpy(stu->id,id);
	strcpy(stu->name,name);
	strcpy(stu->password,password);
	stu->recond = create_recond();
	return stu;
}

Recond* create_recond(void)								//创建学生借还书等操作记录结构体
{
	Recond* recond = malloc(sizeof(Recond));
	recond->borrow_sum = 0;
	recond->head_borrow = create_list_recond();
	recond->repay_sum = 0;
	recond->head_repay = create_list_recond();
	recond->order_sum = 0;
	recond->head_order = create_list_recond();
	recond->overdue_sum = 0;
	recond->head_overdue = create_list_recond();
	return recond;
}

Recond_node* create_node_recond(char* data,long int time_sec)
{
	Recond_node* node = malloc(sizeof(Recond_node));
	node->time_sec = time_sec;
	strcpy(node->data,data);
	node->next = NULL;
	node->front = NULL;
	return node;
}

void add_node_recond(Recond_node* head,char* data,long int time_sec)
{
	Recond_node* node = create_node_recond(data,time_sec);
	if(NULL == head->next)
	{
		head->next = node;
		node->front = head;
		return;
	}
	head->next->front = node;
	node->next = head->next;
	node->front = head;
	head->next = node;
}

void delete_node_recond(Recond_node* node)
{
	if(NULL == node->next)
	{
		node->front->next = NULL;
		free(node);
		return;
	}
	node->front->next = node->next;
	node->next->front = node->front;
	free(node);
}